//例1  求最长公共子序列的和
function search(arr){
    var maxSum = arr[0],
    sum = arr[0];
    for(var i = 0;i<arr.length; i++) {
        if(sum < 0) {
            sum = arr[i];
        } else {
            sum += arr[i];
        }

        if(sum > maxSum) {
            maxSum = sum;
        }
    }
    return maxSum;
}
 
var arr = [-2, 6, -1, -5, 4, -7, 2, 3];
console.log(search(arr));  // 14